import Vue from 'vue';
import Vuex from 'vuex';

Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    openTab: [], //所有打开的路由
    activeIndex: '/main', //激活状态
    isCollapse: false, //是否收缩 侧边栏
  },
  mutations: {
    // 添加tabs
    add_tabs(state, data) {
      this.state.openTab.push(data);
      console.log('[ 添加tabs ] >', this.state.openTab);
    },
    // 删除tabs
    delete_tabs(state, route) {
      let index = 0;
      for (let option of state.openTab) {
        if (option.route === route) {
          break;
        }
        index++;
      }
      this.state.openTab.splice(index, 1);
    },
    // 设置当前激活的tab
    set_active_index(state, index) {
      this.state.activeIndex = index;
    },
    //改变侧边栏
    change_isCollapse(state, isCollapse) {
      isCollapse = this.state.isCollapse;
      this.state.isCollapse = !isCollapse;
    },
  },
});
